package com.zh.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zh.mapstruct.CustomerStructMapper;
import com.zh.pojo.domain.CustomerCar;
import com.zh.mapper.CustomerCarMapper;
import com.zh.pojo.dto.CustomerCarDto;
import com.zh.pojo.vo.CustomerCarVo;
import com.zh.service.ICustomerCarService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zh.utils.AssertUtil;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 客户车辆 服务实现类
 * </p>
 *
 * @author 初四
 * @since 2024-06-13
 */
@Service
public class CustomerCarServiceImpl extends ServiceImpl<CustomerCarMapper, CustomerCar> implements ICustomerCarService {

    /**
     * 查询车辆列表
     * @return
     */
    @Override
    public List<CustomerCar> carList() {
        List<CustomerCar> carList = super.list(new LambdaQueryWrapper<CustomerCar>().eq(CustomerCar::getCustomerId, StpUtil.getLoginIdAsLong()));
        AssertUtil.isNotNull(carList,"车辆列表为空");
        return carList;
    }

    /**
     * 添加车辆
     * @param customerCarDto
     */
    @Override
    public void addCar(CustomerCarDto customerCarDto) {
        // 1、参数判断
        AssertUtil.isNotNull(customerCarDto.getCarPlate(),"车型信息不能为空");
        AssertUtil.isNotNull(customerCarDto.getCarPlate(),"车牌号不能为空");
        // 2、保存车辆信息
        CustomerCar customerCar = CustomerStructMapper.INSTANCE.customerCarDtoConvertToCustomerCar(customerCarDto);
        customerCar.setCustomerId(StpUtil.getLoginIdAsLong());
        customerCar.setCreateTime(new Date());
        super.save(customerCar);


    }
}
